import { User } from './user.entity'
import { Module } from '@nestjs/common'
import { TypeOrmModule } from '@nestjs/typeorm'
import { CryptoUtil } from '../../common/utils/crypto.util'
import { UserController } from './user.controller'
import { UserService } from './user.service'
import { PublicController } from './public.controller'
import { PassportModule } from '@nestjs/passport'
import { JwtModule } from '@nestjs/jwt'
import { jwtConstants } from './constants'
import { LocalStrategy } from './strategies/local.strategy'
import { JwtStrategy } from './strategies/jwt.strategy '
import { Role } from '../role/role.entity'
import { ConfigModule, ConfigService } from '@nestjs/config'

@Module({
  imports: [
    TypeOrmModule.forFeature([User, Role]),
    PassportModule,
    JwtModule.registerAsync({
      imports: [ConfigModule],
      useFactory: async (config: ConfigService) => ({
        secret: config.get('JWT.secretKey'),
        signOptions: {
          expiresIn: config.get('JWT.expiresIn'),
        },
      }),
      inject: [ConfigService],
    }),
    // JwtModule.register({
    //   secret: jwtConstants.secretOrKey,
    //   signOptions: { expiresIn: '3600s' },
    // }),
  ],
  controllers: [UserController, PublicController],
  providers: [UserService, CryptoUtil, LocalStrategy, JwtStrategy],
  exports: [UserService],
})
export class UserModule {}
